﻿using Photo.Core.Dtos.Entity;
using SqlSugar;
using System.Linq.Expressions;

namespace Photo.Respository
{
    /// <summary>
    /// 封装一层接口，仅暴露部分方法给仓储外部调用
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface IRepository<TEntity> where TEntity : BaseEntity, new()
    {
        /// <summary>
        /// 扩展异步添加
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errorText"></param>
        Task InsertAsync(TEntity entity, string errorText = null);
        /// <summary>
        /// 扩展异步添加
        /// </summary>
        /// <param name="list"></param>
        /// <param name="errorText"></param>
        Task InsertAsync(List<TEntity> list, string errorText = null);
        /// <summary>
        /// 扩展异步修改
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errorText"></param>
        Task UpdateAsync(TEntity entity, string errorText = null);
        /// <summary>
        /// 扩展异步修改
        /// </summary>
        /// <param name="list"></param>
        /// <param name="errorText"></param>
        Task UpdateAsync(List<TEntity> list, string errorText = null);
        /// <summary>
        /// 扩展异步修改
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="whereExpression"></param>
        Task<int> UpdateAsync(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, bool>> columns);
        /// <summary>
        /// 扩展异步删除
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errorText"></param>
        Task DeleteAsync(TEntity entity, string errorText = null);
        /// <summary>
        /// 扩展异步删除
        /// </summary>
        /// <param name="list"></param>
        /// <param name="errorText"></param>
        Task DeleteAsync(List<TEntity> list, string errorText = null);
        /// <summary>
        /// 扩展异步删除-按条件
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<int> DeleteAsync(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据主键查询实体
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <returns></returns>
        Task<TEntity> GetAsync(string primaryKey);
        /// <summary>
        /// 扩展根据主键查询实体
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <returns></returns>
        Task<TPurposeEntity> GetAsync<TPurposeEntity>(string primaryKey);
        /// <summary>
        /// 扩展根据主键查询实体
        /// 为空直接显示异常
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<TEntity> GetAsync(string primaryKey, string errorText);
        /// <summary>
        /// 扩展根据主键查询实体
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<TPurposeEntity> GetAsync<TPurposeEntity>(string primaryKey, string errorText);
        /// <summary>
        /// 扩展根据条件查询实体
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件查询实体
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<TPurposeEntity> GetAsync<TPurposeEntity>(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件查询实体
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> whereExpression, string errorText);
        /// <summary>
        /// 扩展根据条件查询实体
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<TPurposeEntity> GetAsync<TPurposeEntity>(Expression<Func<TEntity, bool>> whereExpression, string errorText);
        /// <summary>
        /// 扩展获取列表
        /// </summary>
        /// <returns></returns>
        Task<List<TEntity>> GetListAsync();
        /// <summary>
        /// 扩展获取列表
        /// </summary>
        /// <returns></returns>
        Task<List<TPurposeEntity>> GetListAsync<TPurposeEntity>();
        /// <summary>
        /// 扩展根据条件获取列表
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件获取列表
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<List<TPurposeEntity>> GetListAsync<TPurposeEntity>(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件获取列表
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="orderbyExpression"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderbyExpression, OrderByType type = OrderByType.Asc);
        /// <summary>
        /// 扩展根据条件获取列表
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="orderbyExpression"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        Task<List<TPurposeEntity>> GetListAsync<TPurposeEntity>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderbyExpression, OrderByType type = OrderByType.Asc);
        /// <summary>
        /// 扩展根据主键查询实体指定字段
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<TField> GetFieldAsync<TField>(string primaryKey, Expression<Func<TEntity, TField>> expression);
        /// <summary>
        /// 扩展根据主键查询实体指定字段
        /// </summary>
        /// <param name="primaryKey"></param>
        /// <param name="expression"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<TField> GetFieldAsync<TField>(string primaryKey, Expression<Func<TEntity, TField>> expression, string errorText);
        /// <summary>
        /// 扩展根据条件查询实体指定字段
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<TField> GetFieldAsync<TField>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TField>> expression);
        /// <summary>
        /// 扩展根据条件查询实体指定字段
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="expression"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<TField> GetFieldAsync<TField>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TField>> expression, string errorText);
        /// <summary>
        /// 扩展获取指定字段列表
        /// </summary>
        /// <returns></returns>
        Task<List<TField>> GetFieldListAsync<TField>(Expression<Func<TEntity, TField>> expression);
        /// <summary>
        /// 扩展获取指定字段列表
        /// </summary>
        /// <returns></returns>
        Task<List<TField>> GetFieldListAsync<TField>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TField>> expression);
        /// <summary>
        /// 扩展获取指定字段列表
        /// </summary>
        /// <returns></returns>
        Task<List<TField>> GetFieldListAsync<TField>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TField>> expression, Expression<Func<TEntity, object>> orderbyExpression, OrderByType type = OrderByType.Asc);
        /// <summary>
        /// 扩展获取指定字段去重列表
        /// </summary>
        /// <returns></returns>
        Task<List<TField>> GetFieldDistinctListAsync<TField>(Expression<Func<TEntity, TField>> expression);
        /// <summary>
        /// 扩展获取指定字段去重列表
        /// </summary>
        /// <returns></returns>
        Task<List<TField>> GetFieldDistinctListAsync<TField>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TField>> expression);
        /// <summary>
        /// 扩展获取指定字段去重列表
        /// </summary>
        /// <returns></returns>
        Task<List<TField>> GetFieldDistinctListAsync<TField>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TField>> expression, Expression<Func<TEntity, object>> orderbyExpression, OrderByType type = OrderByType.Asc);
        /// <summary>
        /// 扩展根据条件查询数量
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件获取是否存在
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<bool> AnyAsync(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件获取是否存在
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<bool> AnyAsync(Expression<Func<TEntity, bool>> whereExpression, string errorText);
        /// <summary>
        /// 扩展根据条件获取是否不存在
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<bool> NotAnyAsync(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 扩展根据条件获取是否不存在
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <param name="errorText"></param>
        /// <returns></returns>
        Task<bool> NotAnyAsync(Expression<Func<TEntity, bool>> whereExpression, string errorText);
        /// <summary>
        /// 扩展获取query
        /// </summary>
        /// <returns></returns>
        ISugarQueryable<TEntity> Query();
    }

}
